package com.distribute.application.manage.business;

import java.util.*;
import java.io.File;

import com.distribute.framework.core.web.helper.Utils;
import com.distribute.framework.core.lang.*;
import com.distribute.framework.core.web.node.Export;
import com.distribute.framework.core.lang.Protocol.BeanFormat;
import com.distribute.framework.core.util.Function;
import com.distribute.framework.core.web.util.*;

import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;

import com.distribute.framework.model.*;
import com.distribute.application.manage.*;
/************CTRL_CODE_INPORT************/
import com.alibaba.fastjson.JSON;
/************CTRL_CODE_INPORT************/

/**
 * 账号分组的Controller
 * @author 飞啊飘啊
 */
@SuppressWarnings({"unchecked","rawtypes"})
@flag("ManageRole")
@RestController
@Component(value="manage.business.manageroleController")
public class ManageroleController{
	
	@flag("stuct")
	@RequestMapping("/manage/business/managerole.list.do")
  	public Protocol list() {
  		try{
  			Protocol protocol = Protocol.create(true,null);
  			setFormDataInfo(protocol,null,null);
  			//处理页面的视图数据，比如显示哪些列，自定义显示列等
			ActionHelper.doPageViewFields(ManageRole.class);
  			Map<String,Object> params = setDefaultSort(ActionHelper.getQueryFormParams(ManageRole.class));
			protocol.set("PARAMS",ActionHelper.getQueryFormParams(ManageRole.class));
			protocol.set("fields", Utils.getRequest("fields"));
			Integer iPage = Utils.getInteger("page", 0);
			Integer iSize = Utils.getInteger("size",16);
			params.put("merchant",LoginHelper.getLogin().getId());
			/************CTRL_BEFORE_LIST************/
			/************CTRL_BEFORE_LIST************/
			Page page = ManageRole.page(iPage,iSize,params);//调用获取分页
	    	protocol.setPage(page,new BeanFormat<ManageRole>(){
				public Map format(ManageRole t) {
					return t.toJSON();
				}
			});
			/************CTRL_AFTER_LIST************/
			/************CTRL_AFTER_LIST************/
			return protocol;
		}catch(DefineException e){
			return Protocol.create(false, e.getMessage(), e.getCode());
		}catch(Exception e){		
			e.printStackTrace();
			LoggerHelper.writeError(e);
			return Protocol.create(false,Utils.or(Utils.config("exception.message"), "系统繁忙，请稍后再试"),"exception");
		}
  	}
  	@RequestMapping("/manage/business/managerole.export.do")
  	public Protocol export(HttpServletResponse response) {
  		try{
  			Protocol protocol = Protocol.create(true,null);
  			setFormDataInfo(protocol,null,null);
  			//处理页面的视图数据，比如显示哪些列，自定义显示列等
			ActionHelper.doPageViewFields(ManageRole.class);
  			Map<String,Object> params = setDefaultSort(ActionHelper.getQueryFormParams(ManageRole.class));
  			params.put("idIn", Utils.getString("ids"));
			Integer iPage = Utils.getInteger("page", 0);
			Integer iSize = Utils.getInteger("size",16);
			params.put("merchant",LoginHelper.getLogin().getId());
			/************CTRL_BEFORE_EXPORT************/
			/************CTRL_BEFORE_EXPORT************/
			final Map<String, Object> finalParams = params;
			//调用lazy3q.jar中的导出功能
			//参数说明：(这次导出多少条数据，到数据库查的时候一次查多少条，当前所在第几页,处理器，对应的模型类,要导出哪些字段)
			Utils.export(ManageRole.count(params).intValue(), 100, 0 , new Export(){//new Export这个类，他会根据参数分次查询，边查边写，目的只有一个，就是为了避免把大量的数据放在内存中
				@Override //重载实现Export的getPage方法，Export会分多次调用这个方法
				public Page getPage(Integer page, int size) {//这时的page和size是Export转化过后的当前页，每页查询数					
					return ManageRole.getManageRolePage(page, size, finalParams);
				}
			}, ManageRole.class, Utils.getString("fields").split(","));
			/************CTRL_AFTER_EXPORT************/
			/************CTRL_AFTER_EXPORT************/
			return null;
		}catch(DefineException e){
			return Protocol.create(false, e.getMessage(), e.getCode());
		}catch(Exception e){		
			e.printStackTrace();
			LoggerHelper.writeError(e);
			return Protocol.create(false,Utils.or(Utils.config("exception.message"), "系统繁忙，请稍后再试"),"exception");
		}
  	}
  	
  	
  	@flag("stuct")
  	@RequestMapping("/manage/business/managerole.get.do")
  	public Protocol get() {
  		try{
  			Protocol protocol = Protocol.create(true,null).set("manageRole",new HashMap());
  			ManageRole manageRole = Utils.getObject("", ManageRole.class);
  			if(manageRole!=null){
				protocol.set("manageRole",manageRole.toJSON());
			}
			Long id=Utils.or(Utils.getLong("id"),Utils.getLong("key"));
			String edittype = Utils.getString("edittype");
			if(id==null){
				setFormDataInfo(protocol,edittype,null);
				return protocol.reset(false,null,"args-id-null");
			}			
			manageRole=ManageRole.where.id(id).get();
			if(manageRole==null){
				return protocol.reset(false,"数据不存在","data-not-exist");
			}
			setFormDataInfo(protocol,edittype,manageRole);
			if(manageRole.getMerchant().longValue()!=LoginHelper.getLogin().getId().longValue()){
				protocol.reset(false,"没有权限访问数据","host-no-mate");
				manageRole=null;
			}
			protocol.set("manageRole",manageRole.toJSON());
			if(Utils.equals(Utils.getString("edittype"), "limited")){//表单[修改权限]
				/************LAZY3Q_FORM_UNDEFINE_修改权限************/
				/************LAZY3Q_FORM_UNDEFINE_修改权限************/
			}
			/************CTRL_CODE_GET************/
			/************CTRL_CODE_GET************/
			return protocol;
		}catch(DefineException e){
			return Protocol.create(false, e.getMessage(), e.getCode());
		}catch(Exception e){		
			e.printStackTrace();
			LoggerHelper.writeError(e);
			return Protocol.create(false,Utils.or(Utils.config("exception.message"), "系统繁忙，请稍后再试"),"exception");
		}
  	}
  	
  	
  	
  	@limitVal(2)//查看权限
  	@RequestMapping("/manage/business/managerole.insert.do")
  	public Protocol insert() {
  		try{
			final String requestToken = Utils.getString("manageRoleToken");
			final Date lastToken = Utils.getSession(requestToken);
			if(lastToken==null || (new Date().getTime()-lastToken.getTime())>10000){
				if(requestToken!=null)Utils.setSession(requestToken,new Date());//放入Token时间戳	
				ManageRole.execute(new Function(){
					public <T> T execute(Object... arg0){
						/************CTRL_BEFOR_INSERT************/
						/************CTRL_BEFOR_INSERT************/
						ManageRole manageRole = Utils.getObject("manageRole", ManageRole.class);
						//批量插入处理
						String vValue = ""+(manageRole.getName()==null?"":manageRole.getName());
						String sArray[]={""+vValue};
						if(vValue.startsWith("[*]")){
							vValue=vValue.replace("[*]","");
							sArray=vValue.split("[\\s|\u3000|\\u00a0|,]+");		
						}
						for(String sItem:sArray){
							if(!Utils.empty(sItem))
							manageRole.setName(String.valueOf(sItem));
							//设置默认值
							setDefaultValue(manageRole,"insert");
							manageRole.setMerchant(LoginHelper.getLogin().getId());
								/************CTRL_BEFORE_ADD************/
								/************CTRL_BEFORE_ADD************/
							ManageRole.saveManageRole(manageRole);			
								/************CTRL_AFTER_ADD************/
								/************CTRL_AFTER_ADD************/
						}
						//记录操作日志
						LoggerHelper.writeLog(ManageRole.class,"add","添加了[账号分组]["+manageRole.getName()+"]",LoginHelper.getUserId(), manageRole,manageRole.getId());
						return null;
					}
				});
				
			}else{
				throw new DefineException("repeat-submit-error","对不起，请勿重复提交"+(10-((new Date().getTime()-lastToken.getTime())/1000))+"秒后再试");
			}
			/************CTRL_AFTER_INSERT************/
			/************CTRL_AFTER_INSERT************/
			return Protocol.create(true,"添加[账号分组]数据成功");
		}catch(DefineException e){
			return Protocol.create(false, e.getMessage(), e.getCode());
		}catch(Exception e){		
			e.printStackTrace();
			LoggerHelper.writeError(e);
			return Protocol.create(false,Utils.or(Utils.config("exception.message"), "系统繁忙，请稍后再试"),"exception");
		}
  	}
  	
  	
  	
  	@limitVal(4)//修改权限
  	@RequestMapping("/manage/business/managerole.update.do")
  	public Protocol update() {
  		try{
			final String requestToken = Utils.getString("manageRoleToken");
			final Date lastToken = Utils.getSession(requestToken);
			if(lastToken==null || (new Date().getTime()-lastToken.getTime())>10000){
				if(requestToken!=null)Utils.setSession(requestToken,new Date());//放入Token时间戳	
				ManageRole.execute(new Function(){
					public <T> T execute(Object... arg0){
						/************CTRL_BEFOR_UPDATE************/
						/************CTRL_BEFOR_UPDATE************/
						ManageRole manageRole = Utils.getObject("manageRole", ManageRole.class);
						ManageRole oldManageRole = null;
						String PARAMS = Utils.getString("PARAMS");
						String ids=Utils.getString("ids");
						if(!Utils.empty(PARAMS)){//根据查询条件批量更新
							Map params = Utils.eval(PARAMS);
							params.put("confirm", 1);
							params.put("definex","1=1");
							manageRole.setMerchant(LoginHelper.getLogin().getId());
							
							ManageRole.updateManageRoleByConfirm(ActionHelper.getSetValuesFromModel(manageRole), params);
							LoggerHelper.writeLog(ManageRole.class, "update", 
										"批量修改了[账号分组]",
										LoginHelper.getUserId(),LoggerHelper.getUpdateDescription(null,manageRole,false)
										,null);
							/************CTRL_UPDATE_BY_PARAMS************/
							/************CTRL_UPDATE_BY_PARAMS************/
						}else if(!Utils.empty(ids)){//根据ids批量更新
							Map params = new HashMap();
							params.put("idIn",ids);
							params.put("confirm", 1);
							params.put("definex","1=1");
							ManageRole.updateManageRoleByConfirm(ActionHelper.getSetValuesFromModel(manageRole), params);
							LoggerHelper.writeLog(ManageRole.class, "update", 
										"批量修改了[账号分组]",
										LoginHelper.getUserId(),LoggerHelper.getUpdateDescription(null,manageRole,false)
										,null);
							/************CTRL_UPDATE_BY_IDS************/
							/************CTRL_UPDATE_BY_IDS************/
						}else{
							if(Utils.empty(Utils.getString("all"))){//修改对象非空的字段
								oldManageRole=ManageRole.where.id(manageRole.getId()).get();
								if(oldManageRole==null){
									throw new DefineException("对不起，你没有权限修改当前数据");
								}
								
								ManageRole.updateManageRole$NotNull(manageRole);
								LoggerHelper.writeLog(ManageRole.class, "update", 
										"修改了[账号分组]["+oldManageRole.getName()+"]",
										LoginHelper.getUserId(),LoggerHelper.getUpdateDescription(oldManageRole, manageRole,false)
										,manageRole.getId());
								/************CTRL_UPDATE_NOT_NULL************/
								/************CTRL_UPDATE_NOT_NULL************/
							}else{//修改对象全部字段
								oldManageRole=ManageRole.where.id(manageRole.getId()).get();
								if(oldManageRole==null){
									throw new DefineException("对不起，你没有权限修改当前数据");
								}
								//设置默认值
								manageRole.setUpdateTime(oldManageRole.getUpdateTime());	
								manageRole.setAddTime(oldManageRole.getAddTime());	
								manageRole.setLimits(oldManageRole.getLimits());	
								//设置默认值
								setDefaultValue(manageRole,"update");
								
								//从oldManageRole同步manageRole未set过的值
								manageRole.mergeSet(oldManageRole);
										
								ManageRole.updateManageRole(manageRole);
								LoggerHelper.writeLog(ManageRole.class, "update", 
										"修改了[账号分组]["+oldManageRole.getName()+"]",
										LoginHelper.getUserId(),LoggerHelper.getUpdateDescription(oldManageRole, manageRole,true)
										,manageRole.getId());
								/************CTRL_UPDATE_ALL************/
								/************CTRL_UPDATE_ALL************/
							}
						}
						/************CTRL_CODE_UPDATE************/
						/************CTRL_CODE_UPDATE************/
						return null;
					}
				});
				
			}else{
				throw new DefineException("repeat-submit-error","对不起，请勿重复提交"+(10-((new Date().getTime()-lastToken.getTime())/1000))+"秒后再试");
			}
			/************CTRL_AFTER_UPDATE************/
			/************CTRL_AFTER_UPDATE************/
			return Protocol.create(true,"修改[账号分组]数据成功");
		}catch(DefineException e){
			return Protocol.create(false, e.getMessage(), e.getCode());
		}catch(Exception e){		
			e.printStackTrace();
			LoggerHelper.writeError(e);
			return Protocol.create(false,Utils.or(Utils.config("exception.message"), "系统繁忙，请稍后再试"),"exception");
		}
  	}
  	
  	@limitVal(8)//删除权限
  	@RequestMapping("/manage/business/managerole.delete.do")
  	public Protocol delete() {
  		try{
			ManageRole.execute(new Function(){
				public <T> T execute(Object... arg0){
					Long pid=Utils.getLong("id");
					Long[] ids=new Long[]{pid};
					String strIds=Utils.getString( "ids");
					if(!Utils.empty(strIds) && !strIds.trim().equals("")){//批量删除
						String[] array = strIds.split(",");
						ids=new Long[array.length];
						for(int i=0;i<array.length;i++)
							ids[i]=Long.valueOf(array[i]);
					}
					if(ids.length==0){
						throw new DefineException("args-id-null","参数错误");
					}
					for(Long id:ids){
						ManageRole manageRole = null;
						manageRole=ManageRole.where.id(id).get();
						if(manageRole==null){
							throw new DefineException("对不起，你没有权限修改当前数据");
						}
						ManageRole.delete(id);						
						if(manageRole!=null)//记录操作日志
							LoggerHelper.writeLog(ManageRole.class,"del","删除了[账号分组]["+manageRole.getName()+"]",LoginHelper.getUserId(), manageRole);
						/************CTRL_CODE_DEL************/
						/************CTRL_CODE_DEL************/
					}
					return null;
				}
			});
			return Protocol.create(true,"删除操作成功");
		}catch(DefineException e){
			return Protocol.create(false, e.getMessage(), e.getCode());
		}catch(Exception e){		
			e.printStackTrace();
			LoggerHelper.writeError(e);
			return Protocol.create(false,Utils.or(Utils.config("exception.message"), "系统繁忙，请稍后再试"),"exception");
		}
  	}
	/**
	 * 定义表单修改权限提交
	 */
	@RequestMapping("/manage/business/managerole.limited.do")
	public Protocol limited(){
		try{
			Protocol protocol = Protocol.create(true);
			final String requestToken = Utils.getString("manageRoleToken");
			final Date lastToken = Utils.getSession(requestToken);
			if(lastToken==null || (new Date().getTime()-lastToken.getTime())>10000){
				if(requestToken!=null)Utils.setSession(requestToken,new Date());//放入Token时间戳
				protocol = ManageRole.execute(new Function(){
					public <T> T execute(Object... arg0){
						ManageRole manageRole = Utils.getObject("manageRole", ManageRole.class);
						ManageRole dbManageRole = null;						
						dbManageRole=ManageRole.where.id(manageRole.getId()).get();
						if(dbManageRole==null){
							throw new DefineException("对不起，你没有权限修改当前数据");
						}
						//页面传入参数：manageRole.name,manageRole.limits,
						/************CTRL_FORM_CODE_limited************/
						/************CTRL_FORM_CODE_limited************/
						manageRole.update();
						LoggerHelper.writeLog(ManageRole.class, "modify", 
							"操作了[修改权限]["+dbManageRole.getName()+"]",
							LoginHelper.getUserId(),LoggerHelper.getUpdateDescription(dbManageRole,manageRole,false)
							,dbManageRole.getId());
						return null;
					}
				});
				
			}else{
				throw new DefineException("repeat-submit-error","对不起，请勿重复提交"+(10-((new Date().getTime()-lastToken.getTime())/1000))+"秒后再试");
			}
			/************CTRL_FORM_RETURN_limited************/
			/************CTRL_FORM_RETURN_limited************/
			if(protocol!=null){
				return protocol;
			}
			
			return Protocol.create(true,"[修改权限]操作成功");
		}catch(DefineException e){
			return Protocol.create(false, e.getMessage(), e.getCode());
		}catch(Exception e){		
			e.printStackTrace();
			LoggerHelper.writeError(e);
			return Protocol.create(false,Utils.or(Utils.config("exception.message"), "系统繁忙，请稍后再试"),"exception");
		}
	}

	@RequestMapping("/manage/business/managerole.query.do")
	public Protocol query(){
		try{
			Map<String,Object> params = setDefaultSort(ActionHelper.getQueryFormParams(ManageRole.class));
			params.put("merchant",LoginHelper.getLogin().getId());
			
			String strTerm=Utils.getString("value");//智能搜索时的参数，一般都是主键后面那个字段
			if(!Utils.empty(strTerm)){
				if(strTerm.toLowerCase().startsWith("id:"))//如果查询条件以id:开头，则按ID查询
					params.put("id", strTerm.toLowerCase().replaceFirst("id:", ""));					
				else//按标识查询，模糊查询请带%
				{
					String strDefinex = "";
					strDefinex+=" or name like '%"+strTerm.replaceAll("'", "''")+"%'";
					strDefinex="(2=1 "+strDefinex+")";
					params.put("definex",strDefinex);
				}
			}
			
			Integer iSize = Utils.getInteger("size",10);
			/************CTRL_CODE_QUERY************/
			/************CTRL_CODE_QUERY************/
			
			List<ManageRole> list = ManageRole.page(0,iSize,params).getResult();
			
			Boolean bObject=Utils.getBoolean("object",false);//是否需要整个数据对象
			List<Map> result = new java.util.ArrayList();
			for(ManageRole manageRole:list){
				Map map = new HashMap();
				map.put("key",manageRole.getId().toString());
				map.put("value", Utils.js(manageRole.getKeyValue()));
				if(bObject==true){
					map.put("object",manageRole);
				}
				result.add(map);
			}
			/************CTRL_AFTER_QUERY************/
			/************CTRL_AFTER_QUERY************/
			
			return Protocol.create().setList(result);
		}catch(DefineException e){
			return Protocol.create(false, e.getMessage(), e.getCode());
		}catch(Exception e){		
			e.printStackTrace();
			LoggerHelper.writeError(e);
			return Protocol.create(false,Utils.or(Utils.config("exception.message"), "系统繁忙，请稍后再试"),"exception");
		}
	}
	/************CTRL_DEFINE_CODE************/
	/************CTRL_DEFINE_CODE************/
  	
  	/**获取子项列表**/
	public static Map getItems(){
		Map map = new HashMap();
		/************CTRL_DEFINE_ITEMS************/
		String strJson = null;
		try {
			strJson = Utils.readFile(ManageroleController.class.getResourceAsStream("../projects.json"), "UTF-8");
		} catch (Exception e) {
			e.printStackTrace();
		}
		List<Map> list = (List) JSON.parse(strJson);
		List<Map> limits$items = new ArrayList();
		for(Map item:list){
			limits$items.add(Utils.add("key", item.get("spName")).add("value", item.get("spName")));
		}
		map.put("limits$items", limits$items);
		/************CTRL_DEFINE_ITEMS************/
		return map;
	}
  	
  	/**
	* 设置排序
	**/
  	private Map<String,Object> setDefaultSort(Map<String, Object> params) {
		String strAsc=ManageRole.C.get(Utils.forMat(Utils.getString("asc")));//升序字段
		params.put("asc", strAsc);//放入查询条件
		String strDesc=ManageRole.C.get(Utils.forMat(Utils.getString("desc")));//降序字段
		params.put("desc",strDesc);//放入查询条件 
		if(Utils.empty(strAsc) && Utils.empty(strDesc))//如果未传入排序字段
			params.put("desc","id");//那么，默认以主键降序，传给Dao层
		return params;
	}
  	/**
	* 设置默认值
	**/
	public void setDefaultValue(ManageRole manageRole,String type){
		if(type.equals("insert")){//添加时			
			if(manageRole.getUpdateTime()==null)
				manageRole.setUpdateTime(new Date());
			if(manageRole.getAddTime()==null)
				manageRole.setAddTime(new Date());
			if(manageRole.getStatus()==null)
				manageRole.setStatus((short)1);
		}else if(type.equals("update")){//编辑时
			manageRole.setUpdateTime(new Date());
		}
	}
	/**
	* 设置表单信息
	**/
	public void setFormDataInfo(Protocol protocol,String edittype,ManageRole manageRole){
		Map model = new HashMap();
		model.put("name","manageRole");
		model.put("caption","账号分组");
		model.put("type","table");
		model.put("icon","icon-friend");
		model.put("PK","id");
		model.put("add",true);
		model.put("update",true);
		model.put("details",true);
		List propertys = new ArrayList();
		List submits = new ArrayList();
		model.put("propertys", propertys);
		model.put("submits", submits);	
		protocol.set("model", model);
		if(Utils.empty(edittype)){
		propertys.add(Utils.add("name","remarks").add("cell","content").add("caption","备注说明").add("input","textarea").add("primary",false).add("length",256));
		propertys.add(Utils.add("name","status").add("cell","coner").add("caption","状　　态").add("input","select").add("primary",false).add("length",2).add("options",new Object[]{Utils.add("text","正常").add("value","1"),Utils.add("text","无效").add("value","0")}));
		}
		else if(edittype.equals("limited")){
			
				model.put("title","修改权限");
			
				propertys.add(Utils.add("name","name").add("caption","组 名 称").add("input","label").add("primary",false).add("length",32).add("notNull",true).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")));
			
			
				propertys.add(Utils.add("name","limits").add("caption","权限配置").add("input","checkbox").add("primary",false).add("length",512).add("notNull",true).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")));
			
				submits.add(Utils.add("name","submiter").add("value","完成").add("title","完成").add("icon","icon-weibiaoti8"));
			
		}
		else{
			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","name").add("caption","组 名 称").add("input","text").add("primary",false).add("length",32).add("notNull",true).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")));
			}
			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","remarks").add("caption","备注说明").add("input","textarea").add("primary",false).add("length",256).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")));
			}
			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"none":"none")).equals("none")){
				propertys.add(Utils.add("name","updateTime").add("caption","修改时间").add("input","datetime").add("primary",false).add("length",19).add("notNull",true).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"none":"none")));
			}
			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"none":"none")).equals("none")){
				propertys.add(Utils.add("name","addTime").add("caption","添加时间").add("input","datetime").add("primary",false).add("length",19).add("notNull",true).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"none":"none")));
			}
			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"none":"editable")).equals("none")){
				propertys.add(Utils.add("name","status").add("caption","状　　态").add("input","select").add("primary",false).add("length",2).add("notNull",true).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"none":"editable")).add("options",new Object[]{Utils.add("text","正常").add("value","1"),Utils.add("text","无效").add("value","0")}));
			}
			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","merchant").add("caption","所属品牌").add("input","query").add("primary",false).add("length",8).add("notNull",true).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).add("relate","Merchant"));
			}
			submits.add(Utils.add("name","submiter").add("value","完成").add("title","完成").add("icon","icon-weibiaoti8"));
		}
	}
  
}